import 'package:flutter/material.dart';
import 'package:flutter_base_plugin/flutter_base_plugin.dart';
import '../../config/k_color.dart';
import 'vm/user_view_model.dart';

class UserPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _userPageState();
  }
}

// ignore: camel_case_types
class _userPageState extends BaseProviderState<UserViewModel, UserPage> {
  @override
  void buildCreate() {
    // TODO: implement buildCreate
    setAppBarTitle("用户列表");
  }

  @override
  UserViewModel buildViewModel() {
    // TODO: implement buildViewModel
    return UserViewModel();
  }

  @override
  Widget buildWidget(UserViewModel viewModel, BuildContext context) {
    // TODO: implement buildWidget
    return EasyRefresh(
      header: ClassicalHeader(
        refreshText: "下拉刷新···",
        refreshReadyText: "松开开始刷新数据",
        refreshingText: "数据刷新中···",
        refreshedText: "刷新成功！",
        refreshFailedText: "刷新失败，请重试！",
        noMoreText: "暂无更多数据~",
        showInfo: true,
        infoText: "更新时间： %T",
      ),
      footer: ClassicalFooter(
        loadText: "loadText",
        loadReadyText: "loadReadyText",
        loadingText: "加载中…",
        loadedText: "松手开始加载数据",
        loadFailedText: "数据加载失败，请重试！",
        noMoreText: "暂无更多数据~",
        showInfo: true,
        infoText: "更新时间：%T",
      ),
      onRefresh: () => viewModel.onLoading(),
      onLoad: () => viewModel.onLoadingMore(),
      controller: viewModel.controller,
      child: ListView.builder(
        itemCount: viewModel.dataList.length,
        itemBuilder: (context, index) {
          return _buildGoodsListItem(viewModel.dataList[index]);
        },
      ),
    );
  }

  Widget _buildGoodsListItem(item) {
    return InkWell(
      onTap: () {},
      child: Container(
        color: KColors.white,
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Container(
                  width: 180.h,
                  height: 180.h,
                  child: Image.network(
                    " HttpConstant.imageUrl + ",
                    fit: BoxFit.cover,
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Container(
                    height: 180.h,
                    margin: EdgeInsets.only(left: 10),
                    // color: Colors.red,
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text("${item.name}",
                            maxLines: 2, overflow: TextOverflow.ellipsis),
                        Row(
                          children: <Widget>[
                            Container(
                              height: 36.h,
                              margin: EdgeInsets.only(right: 10),
                              padding: EdgeInsets.fromLTRB(10, 0, 10, 0),

                              //注意 如果Container里面加上decoration属性，这个时候color属性必须得放在BoxDecoration
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(10),
                                color: Color.fromRGBO(230, 230, 230, 0.9),
                              ),

                              child: Text("4g"),
                            ),
                            Container(
                              height: 36.h,
                              margin: EdgeInsets.only(right: 10),
                              padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(10),
                                color: Color.fromRGBO(230, 230, 230, 0.9),
                              ),
                              child: Text("126"),
                            ),
                          ],
                        ),
                        Text(
                          "¥${item.birthday}",
                          style: TextStyle(color: Colors.red, fontSize: 16),
                        )
                      ],
                    ),
                  ),
                )
              ],
            ),
            Divider(
              thickness: 2.h,
            ),
          ],
        ),
      ),
    );
  }

  @override
  void onDestruction() {
    // TODO: implement onDestruction
  }
}
